use std::collections::VecDeque;

struct Solution;

impl Solution {
    pub fn deck_revealed_increasing(deck: Vec<i32>) -> Vec<i32> {
        if deck.len() == 1 {
            return deck;
        }

        let mut res = VecDeque::new();
        let mut deck = deck;
        deck.sort();
        let len = deck.len();
        res.push_front(deck.pop().unwrap());
        res.push_front(deck.pop().unwrap());
        for _ in 2..len {
            let end = res.pop_back().unwrap();
            let val = deck.pop().unwrap();
            res.push_front(end);
            res.push_front(val);
        }

        Vec::from(res)
    }
}

pub fn reveal_cards_in_increasing_order(deck: Vec<i32>) -> Vec<i32> {
    Solution::deck_revealed_increasing(deck)
}

#[test]
fn test() {
    let deck = vec![17, 13, 11, 2, 3, 5, 7];
    let res = reveal_cards_in_increasing_order(deck);
    println!("{:?}", res);
    assert_eq!(res, vec![2, 13, 3, 11, 5, 17, 7]);
}

fn main() {

}
